﻿using System;
using System.Threading;
using System.Windows.Forms;
using PhiStore.Threading;

namespace PhiStore.Tests
{
    public partial class TestUI : Form
    {
        public TestUI()
        {
            InitializeComponent();
        }
        private void TestUI_Load(object sender, EventArgs e)
        {
            Booster.Boost(new LogViewerBooster());
        }

        private void BestCaseButton_Click(object sender, EventArgs e)
        {
            ITest bestcase = new BestCase.BestCase((uint)replicationNumber.Value, (int)clientsCount.Value, use2PCcheck.Checked, compress.Checked, encrypt.Checked);
            RunTest(bestcase);
        }

        private void RunTest(ITest test)
        {
            PhiStore.Threading.Booster.Boost(test);
            while (!test.IsComplete())
            {
                Output.Text = "Running...";
                Output.Update();
                Thread.Sleep(1000);
            }

            Output.Text = test.getResults();
        }

        private void shutdown_Click(object sender, EventArgs e)
        {
            ITest shutdown = new ShutdownTest((uint)replicationNumber.Value, (int)clientsCount.Value, use2PCcheck.Checked);
            RunTest(shutdown);
        }

        private void GCTest_Click(object sender, EventArgs e)
        {
            ITest garbage = new GarbageCollect.GarbageCollectTest((uint)replicationNumber.Value, (int)clientsCount.Value, use2PCcheck.Checked);
            RunTest(garbage);
        }

        private void StopNGoButton_Click(object sender, EventArgs e)
        {
            ITest StopNGo = new StopNGo((uint)replicationNumber.Value, (int)clientsCount.Value, use2PCcheck.Checked);
            RunTest(StopNGo);
        }

        private void prefetchButton_Click(object sender, EventArgs e)
        {
            ITest prefetch = new PrefetchTest((uint)replicationNumber.Value, (int)clientsCount.Value, use2PCcheck.Checked);
            RunTest(prefetch);
        }

        private void NegotiateButton_Click(object sender, EventArgs e)
        {
            ITest nego = new NegotiationTest((uint)replicationNumber.Value, (int)clientsCount.Value, use2PCcheck.Checked);
            RunTest(nego);
        }

        private void FailureButton_Click(object sender, EventArgs e)
        {
            ITest fail = new FailureTest((uint)replicationNumber.Value, (int)clientsCount.Value, use2PCcheck.Checked);
            RunTest(fail);
        }

       

    }
}
